package com.plate.bpm.web.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.plate.bpm.web.model.ConsoleBean;
import com.plate.bpm.web.persistence.ConsoleMapper;

/**
 *作者： 李志刚
 *时间：2015-8-25
 */
@Service
@Transactional
public class ConsoleServiceImpl {
	
	@Autowired
	private ConsoleMapper mapper;
	
	@Resource
	private ProcessEngine processEngine;
	/**
	 * <功能简述>查询管理表
			* <功能详细描述>根君活动id查询当前处理组
			* @param activitiId
			* @return
			* @see [类、类#方法、类#成员]
	 */
	public ConsoleBean getManagerFlow(String activitiId, String processKey){
		return mapper.getManagerFlow(activitiId,processKey);
	}
	
	/**
	 * <功能简述>查询岗位名称
	 * <功能详细描述>根据id查询当前处理组
	 * @param activitiId
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	public String getOrgNameByRoleId(String id){
		return mapper.getOrgNameByRoleId(id);
	}
	
	/**
	 * <功能简述>保存
			* <功能详细描述>
			* @see [类、类#方法、类#成员]
	 */
	public void save(ConsoleBean bean){
		mapper.save(bean);
	}
	/**
	 * <功能简述>修改
			* <功能详细描述>
			* @see [类、类#方法、类#成员]
	 */
	public void update(ConsoleBean bean){
		mapper.update(bean);
	}
	
	/**
	 * <功能简述>获取岗位
			* <功能详细描述>根据活动id和流程key 获取岗位id
			* @param activitiId
			* @param prcDefinitionKey
			* @return
			* @see [类、类#方法、类#成员]
	 */
	public String getGroupId(String activitiId, String prcDefinitionKey){
		if(null == activitiId || "".equals(activitiId)){
			System.out.println("error： activitiID  is not empty ！" );
			return null;
		}
		if(null == prcDefinitionKey || "".equals(prcDefinitionKey)){
			System.out.println("error： prcDefinitionKey  is not empty ！" );
			return null;
		}
		return mapper.getGroupId(prcDefinitionKey,activitiId);
	}
	
	 /**
     * 流程实例.
     */
    public List<ProcessInstance> findProcessInstances() {
        RuntimeService runtimeService = processEngine.getRuntimeService();
        long count = runtimeService.createProcessInstanceQuery().count();
        List<ProcessInstance> processInstances = runtimeService
                .createProcessInstanceQuery().list();

        return processInstances;
    }
}

	